package com.choudou5.webflux.dao;

import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@AllArgsConstructor
public class RedisDemoDao implements DemoDao {

    private static final String KEY_TEMPLATE = "flux:%s:%s";

    private ReactiveStringRedisTemplate template;

    @Override
    public Flux<Long> getIncrement(String type, String userId) {
        Mono<Long> ids = template.opsForValue().increment(String.format(KEY_TEMPLATE, type, userId));
        return ids.flux();
    }

}
